package com.bjpowernode.springboot.web;

import com.bjpowernode.springboot.domain.RefPartExcel;

import com.bjpowernode.springboot.domain.Student;
import com.bjpowernode.springboot.domain.Students;
import com.bjpowernode.springboot.service.StudentService;
import com.bjpowernode.springboot.util.ExcelUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Copyright (C), 2021-2021, 颜子初
 * Author: yan
 * Date: 2021/11/12 14:41
 * FileName: ExcelController
 * Description: excel
 */
@RestController
@RequestMapping("/excelup")
public class ExcelController {

    @RequestMapping(value = "/fileUpload",method = RequestMethod.POST,
            consumes = "application/json",produces = "application/json")
    public Map<String, Object> fileUpload(HttpServletRequest request,@RequestParam("file") MultipartFile file) {
        Map<String, Object> map = new HashMap<String, Object>();
        // 判断文件是否为空
        if (file.isEmpty()) {
            try {
                List<Student> students = ExcelUtil .readExcel(file,Student.class);
                System.out.println(students.size());
                for(Student ep : students){
                    System.out.println(ep.toString());
                }
                //........逻辑
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return map;
    }
}
